package date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Text {
    public static void main(String[] args) {
        /*//格式化
        Date d = new Date();
        SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = s.format(d);
        System.out.println(format);

        //解析
        String day = "2020-01-02 14:25:36";
        Date r = null;
        try {
            r = s.parse(day);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        System.out.println(r);*/

        //Calendar
        Calendar i = Calendar.getInstance();
        int date = i.get(Calendar.DATE);
        System.out.println(date);
        int year = i.get(Calendar.YEAR);
        System.out.println(year);
        int month = i.get(Calendar.MONTH);
        System.out.println(month+1);
        int week = i.get(Calendar.WEEK_OF_MONTH);
        System.out.println(week);
        i.set(Calendar.YEAR,2022);
        i.set(Calendar.MONTH,9);
        i.set(Calendar.DAY_OF_MONTH,1);
        int q = i.get(Calendar.DAY_OF_WEEK);
        System.out.println(getWeek(q));
    }
    public static String getWeek(int week) {
        String[] s = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
        return s[week];
    }
}
